web/src/pages/[...section].astro
315 lines · 8296 bytes
1---
2
3
4import Layout from '@layouts/Layout.astro';
5import Button from '@components/form/Button.astro';
6import Main from '@components/scafold/MainCard.astro';
7import ServiceList from '@components/things/ServiceList.astro';
8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
9import { fetchData, slugify } from '@utils/fetch-data';
10import { parseMarkdown } from '@utils/parse-markdown';
11
12interface Props {
13 slug: string,
14 title: string,
15 services: Service[],
16 intro?: string,
17 notableMentions?: ShortService[] | string,
18 furtherInfo?: string,
19 wordOfWarning?: string,
20 alternativeTo?: string[];
21 categoryName: string,
22 otherSections: Section[],
23}
24
25const {
26 title, otherSections, services, notableMentions, furtherInfo, wordOfWarning,
27 alternativeTo, categoryName, intro,
28} = Astro.props;
29
30/**
31 * Make a list of keywords, for the <meta keywords> tag
32 */
33const makeKeyWordTag = () => {
34 const keywords = [];
35 keywords.push(`free and open source ${title} software`);
36 keywords.push(`private ${title} comparison`);
37 (alternativeTo || []).forEach((alt: string) => {
38 keywords.push(`privacy-respecting ${alt} alternative`);
39 keywords.push(`free open source ${alt} alternative`);
40 });
41 (services || []).forEach((serv: Service) => {
42 keywords.push(serv.name);
43 });
44 keywords.push('ad free');
45 keywords.push('open source software');
46 keywords.push('privacy respecting apps');
47 return keywords.join(', ');
48};
49
50/**
51 * Make a page title
52 */
53const makePageTitle = () => {
54 return `${title} | Awesome Privacy`;
55};
56
57/**
58 * Make a string page intro, for the description tag
59 */
60const makeDescriptionTag = () => {
61 let description = `Privacy respecting ${title}. `;
62 if (services && services.length > 0) {
63 const serviceList = services.map((serv: Service) => serv.name);
64 description += `Compare ${serviceList.join(' vs ')} and more private, open source apps and services now. `
65 } else {
66 description += `Find private apps and services. This section is still a work in progress. `;
67 }
68 if (alternativeTo && alternativeTo.length > 0) {
69 description += `The best secure encrypted alternatives to ${alternativeTo.join(', ')} in 2024. `;
70 }
71 description += 'All this, and many more free and awesome tools and software.'
72 return description;
73};
74
75export async function getStaticPaths() {
76 const pages = await fetchData().then((data) => {
77 const results: Array<Props> = [];
78 if (!data || !data.categories) return results;
79 (data as AwesomePrivacy).categories.forEach((category) => {
80 const sections = category.sections.map((section) => ({
81 slug: `${slugify(category.name)}/${slugify(section.name)}`,
82 title: section.name,
83 services: section.services,
84 intro: section.intro,
85 notableMentions: section.notableMentions,
86 furtherInfo: section.furtherInfo,
87 wordOfWarning: section.wordOfWarning,
88 alternativeTo: section.alternativeTo,
89 categoryName: category.name,
90 otherSections: category.sections,
91 }));
92 results.push(...sections);
93 });
94 return results;
95 });
96
97 return pages.map((props: Props) => {
98 return {params: { section: props.slug }, props };
99 });
100}
101
102const makePaginationLinks = () => {
103 const index = otherSections.findIndex(section => section.name === title);
104 const previousSection = index > 0 ? otherSections[index - 1].name : null;
105 const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null;
106 return { previous: previousSection, next: nextSection };
107};
108
109const { previous, next } = makePaginationLinks();
110
111---
112
113<Layout title={makePageTitle()} keywords={makeKeyWordTag()} description={makeDescriptionTag()} >
114 <Main>
115
116 <h2>{title}</h2>
117
118 {intro && (
119 <section class="intro">
120 <p set:html={parseMarkdown(intro)}></p>
121 </section>
122 )}
123
124 <ServiceList services={services} sectionName={title} categoryName={categoryName} />
125
126 <details class="about-this-page">
127 <summary>Objective of this page</summary>
128 <p>
129 Find the best free, open source, E2E encrypted and private alternative to
130 {(alternativeTo || []).map((alt) => (<span>{alt}, </span>))} now.
131 </p>
132 <p>
133 Compare {(services || []).map((serv) => (<span>{serv.name} vs </span>))}
134 </p>
135 <p>
136 Discover the best {title} tools for Android, iPhone, Linux, PC and Chrome to download now.
137 And choose secure, self-hosted, peer-to-peer and independant alternatives in 2024
138 </p>
139 <p>
140 <b>Stop the invasion of privacy from big tech, improve data security stay safe.</b>
141 </p>
142 </details>
143
144
145 {notableMentions && (
146 <section class="notable-mentions">
147 <h3>Notable Mentions</h3>
148 { Array.isArray(notableMentions) ?
149 <ul>
150 {notableMentions.map((mention) => (
151 <li>
152 <a href={mention.url}>{mention.name}</a>
153 {mention.description && (
154 <span>- </span>
155 <span set:html={parseMarkdown(mention.description)}></span>
156 )}
157 </li>
158 ))}
159 </ul> :
160 <p set:html={parseMarkdown(notableMentions)}></p>
161 }
162 </section>
163 )}
164
165 {furtherInfo && (
166 <section class="further-info">
167 <h3>Notes</h3>
168 <p set:html={parseMarkdown(furtherInfo)}></p>
169 </section>
170 )}
171
172 {wordOfWarning && (
173 <section class="word-of-warning">
174 <h3>Word of Warning</h3>
175 <p set:html={parseMarkdown(wordOfWarning)}></p>
176 </section>
177 )}
178
179 {services.length > 0 && (<section class="submit-alternative">
180 <h3>Submit New Entry</h3>
181 <p>
182 Are we missing anything?
183 You can help us improve this page, by <a href="/submit">submitting a new entry</a>
184 </p>
185 </section>
186 )}
187
188 <div class="pagination-navigation">
189 { previous ? (
190 <Button url={`/${slugify(categoryName)}/${slugify(previous)}`}>
191 <span>← Previous</span>
192 <p>{previous}</p>
193 </Button>
194 ) : <p class="nothing"></p>}
195 <a href={`/${slugify(categoryName)}`} class="go-to-category">
196 View all in {categoryName} ({otherSections.length})
197 </a>
198 { next && (
199 <Button url={`/${slugify(categoryName)}/${slugify(next)}`}>
200 <span>Next →</span>
201 <p>{next}</p>
202 </Button>
203 )}
204 </div>
205 </Main>
206</Layout>
207
208<style lang="scss">
209
210section {
211 padding-bottom: 1rem;
212 &:not(:last-child) {
213 border-bottom: 2px solid var(--accent-3);
214 }
215}
216
217h2 {
218 font-size: 2rem;
219 margin: -2rem 0 2rem -2rem;
220 box-shadow: 6px 6px 0 var(--foreground);
221 background: var(--accent);
222 color: var(--accent-fg);
223 width: fit-content;
224 padding: 0.25rem 0.5rem;
225 }
226
227.pagination-navigation {
228 display: flex;
229 justify-content: space-between;
230 align-items: center;
231 padding: 1rem 0;
232 :global(.button) {
233 min-width: 120px;
234 width: fit-content;
235 padding: 0.25rem 1rem;
236 text-align: right;
237 &:first-child { text-align: left; }
238 p {
239 margin: 0;
240 font-weight: normal;
241 font-size: 1rem;
242 }
243 span {
244 font-size: 0.8rem;
245 }
246
247 }
248 .nothing {
249 width: 120px;
250 }
251 .go-to-category {
252 color: var(--foreground);
253 font-size: 0.8rem;
254 opacity: 0.5;
255 @media (max-width: 768px) {
256 display: none;
257 }
258 }
259}
260
261.intro {
262 font-style: italic;
263 opacity: 0.7;
264}
265
266
267.further-info, .notable-mentions, .word-of-warning, .submit-alternative {
268 h3 {
269 font-size: 1.4rem;
270 margin: 1rem 0;
271 }
272 :global(p) {
273 font-size: 0.9rem;
274 opacity: 0.7;
275 :global(strong) {
276 font-weight: 500;
277 }
278 :global(a) {
279 color: var(--foreground);
280 transition: all 0.15s ease-in-out;
281 &:hover {
282 color: var(--accent);
283 }
284 }
285 }
286 :global(strong) {
287 font-weight: 500;
288 }
289 :global(h4) {
290 font-size: 1.2rem;
291 margin: 0.5rem 0 0 0;
292 }
293 :global(ul) {
294 list-style: circle;
295 padding-left: 1rem;
296 font-size: 0.9rem;
297 opacity: 0.7;
298 li {
299 margin-bottom: 0.25rem;
300 :global(p) {
301 display: inline;
302 }
303 }
304 }
305}
306.about-this-page {
307 summary {
308 display: none;
309 }
310 font-size: 0.9rem;
311 opacity: 0.7;
312}
313
314
315</style>